# 使用Git绝对路径
$gitPath = "C:\Program Files\Git\bin\git.exe"
$projectPath = "d:\MCP"

# 验证Git安装
try {
    & $gitPath --version
    Write-Host "Git is installed correctly."
} catch {
    Write-Host "Git is not installed correctly."
    pause
    exit 1
}

# 配置Git用户信息
& $gitPath config --global user.name "yuzh0618"
& $gitPath config --global user.email "yuzh0618@126.com"
Write-Host "Git user configured."

# 切换到项目目录
Set-Location -Path $projectPath
Write-Host "Changed directory to $projectPath"

# 初始化Git仓库
& $gitPath init
Write-Host "Git repository initialized."

# 添加远程仓库
& $gitPath remote add origin https://gitee.com/yuzh0618/mess-mcp.git
Write-Host "Remote repository added."

# 列出当前目录文件
dir
Write-Host "Files in directory listed."

# 添加所有文件
& $gitPath add .
if ($LASTEXITCODE -eq 0) {
    Write-Host "Files added to staging area successfully."
} else {
    Write-Host "Failed to add files to staging area."
    pause
    exit 1
}

# 查看状态
& $gitPath status
Write-Host "Git status checked."

# 提交代码
& $gitPath commit -m "Initial commit"
if ($LASTEXITCODE -eq 0) {
    Write-Host "Files committed successfully."
} else {
    Write-Host "Failed to commit files."
    pause
    exit 1
}

# 推送代码到远程仓库
try {
    & $gitPath push -u origin master
    Write-Host "Code pushed successfully!"
} catch {
    Write-Host "Failed to push code. Check network connection and Gitee credentials."
}

pause